package com.chenfan.mcn.dao;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chenfan.mcn.constant.NumberCst;
import com.chenfan.common.extension.mybatisplus.enhanced.EnhancedBaseMapper;
import com.chenfan.mcn.model.CalculationDevided;
import com.chenfan.mcn.model.ContractExcutionOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author tangwei
 * Date:     2021/1/26 20:12
 * Description: 收入合同执行单-计算分成
 */
@Mapper
public interface CalculationDevidedMapper extends EnhancedBaseMapper<CalculationDevided> {

    /**
     * 执行单已执行金额
     * @param beginOfMonth
     * @param endOfMonth
     * @return
     */
    BigDecimal excutedAmount(@Param("beginOfMonth") Date beginOfMonth, @Param("endOfMonth") Date endOfMonth);

    /**
     * 刷新计算分成
     *
     * @return List<ContractExcutionOrder>
     */
    List<ContractExcutionOrder> refreshCalculationDevided();

    /**
     * 修改计算分成
     *
     * @param calculationDevided 计算分成
     * @return Integer
     */
    Integer updateDetail(@Param("dto") CalculationDevided calculationDevided);

    /**
     * 通过执行单ID获取计算分成
     * @param excutionOrderId
     * @return
     */
    default CalculationDevided getByExecuteId(Long excutionOrderId) {
        return this.selectOne(Wrappers.lambdaQuery(CalculationDevided.class)
                .eq(CalculationDevided::getExcutionOrderId, excutionOrderId).eq(CalculationDevided::getIsDelete, NumberCst.ZERO));
    }
}